<template>
  <div class="echartsBox">
    <div id="locationEcharts" class="allWidthHeight" />
  </div>
</template>
<script>
import * as echarts from 'echarts'
export default {
  props: {},
  data() {
    return {
      myChart: null,
      value1: '',
      rotation: 0,
      timeInterval: () => {},
      imageUrl: require('@/assets/images/pao.png')
    }
  },
  watch: {},
  async mounted() {},
  methods: {
    infoSize() {
      this.myChart.resize()
    },

    /* echarts */
    setLocationEcharts(num) {
      let data = [
        num.allRate,
        num.outRate,
        num.inRate,
        num.allotRate,
        num.changeRate
      ]
      let titlename = ['总库位', '日出库', '日入库', '日调拨', '流量']
      let valdata = [
        num.allRate,
        num.outRate,
        num.inRate,
        num.allotRate,
        num.changeRate
      ]
      let myColor = ['#1089E7', '#F57474', '#56D0E3', '#F8B448', '#8B78F6']
      const option = {
        //图标位置
        grid: {
          top: '0',
          left: '18%',
          right: '17%',
          bottom: '10%'
        },
        xAxis: {
          show: false
        },
        yAxis: [
          {
            show: true,
            data: titlename,
            inverse: true,
            axisLine: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              color: '#fff',
              rich: {
                lg: {
                  backgroundColor: '#339911',
                  color: '#fff',
                  borderRadius: 15,
                  // padding: 5,
                  align: 'center',
                  width: 15,
                  height: 30
                }
              }
            }
          },
          {
            show: true,
            inverse: true,
            data: valdata,
            axisLabel: {
              formatter: '{value}%',
              textStyle: {
                fontSize: 12,
                color: '#fff'
              }
            },
            axisLine: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            }
          }
        ],
        series: [
          {
            name: '条',
            type: 'bar',
            yAxisIndex: 0,
            data: data,
            barCategoryGap: 50,
            barWidth: 20,
            itemStyle: {
              borderRadius: 20,
              color: function (params) {
                var num = myColor.length
                return myColor[params.dataIndex % num]
              }
            },
            label: {
              show: false,
              position: 'right',
              formatter: '{c}%',
              color: '#fff',
              verticalAlign: 'middle', // 垂直居中
              align: 'center' // 水平居中
            }
          },
          {
            name: '框',
            type: 'bar',
            yAxisIndex: 1,
            barCategoryGap: 50,
            data: [100, 100, 100, 100, 100],
            barWidth: 21,
            itemStyle: {
              color: 'none',
              borderColor: '#00c1de',
              borderWidth: 1,
              borderRadius: 15
            }
          }
        ]
      }
      if (
        this.myChart != null &&
        this.myChart !== '' &&
        this.myChart !== undefined
      ) {
        this.myChart.dispose() // 销毁
      }
      this.myChart = echarts.init(document.getElementById('locationEcharts'))
      this.myChart.clear()
      this.myChart.setOption(option, true)
    }
  }
}
</script>
<style lang='scss' scoped>
.echartsBox {
  width: 100%;
  padding: 0 15px;
  height: calc(100% - 40px);
}
</style>
